package com.kl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kl.em.ConstantEnum;
import com.kl.em.Result;
import com.kl.entity.Waybill;
import com.kl.mapper.WaybillMapper;
import com.kl.service.IWaybillService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2021-10-30
 */
@Service
public class WaybillServiceImpl extends ServiceImpl<WaybillMapper, Waybill> implements IWaybillService {


    @Autowired
    private WaybillMapper waybillMapper;

    @Override
    public List<Waybill> likeWaybill(String logisticsStatus) {
        QueryWrapper<Waybill> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("logistics_status",logisticsStatus);
        List<Waybill> waybills = waybillMapper.selectList(queryWrapper);
        return waybills;
    }

    @Override
    public Result addWaybill(Waybill waybill) {
        int insert = waybillMapper.insert(waybill);
        if(insert <= 0){
            return Result.build(ConstantEnum.ERROR);
        }
        return Result.build(ConstantEnum.SUCCESS);
    }

    @Override
    public Result deleteWaybill(Long waybillId) {
        int i = waybillMapper.deleteById(waybillId);
        if(i <= 0){
            return Result.build(ConstantEnum.ERROR);
        }
        return Result.build(ConstantEnum.SUCCESS);
    }

    @Override
    public Result updateWaybill(Waybill waybill2) {
//        QueryWrapper<Waybill> queryWrapper = new QueryWrapper();
//        queryWrapper.eq("waybill_id",waybill2.getWaybillId());
        int update = waybillMapper.updateById(waybill2);
        if(update <= 0){
            return Result.build(ConstantEnum.ERROR);
        }
        return Result.build(ConstantEnum.SUCCESS);
    }


}
